package swing;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.WindowConstants;

import controlador.ControladorAbmClientes;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class ClienteAlta extends Vista{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JLabel jLabelidCliente;
	private JLabel jLabelRazonSocial;
	private JLabel jLabelDireccion;
	private JLabel jLabelMensaje;
	private JButton jButtonLimpiar;
	private JButton jButtonCancelar;
	private JButton jButtonAltaCliente;
	private JTextField jTextFieldTelefono;
	private JTextField jTextFieldDireccion;
	private JTextField jTextFieldRazonSocial;
	private JTextField jTextFieldidCliente;
	private JLabel jLabelTelefono;

	public ClienteAlta(){
		super();
		initGUI();
	}
	
	@Override
	public void actualizar() {
		// TODO Auto-generated method stub
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(null);
			this.setTitle("Alta de Cliente");
			this.setVisible(true);

			{
				jLabelidCliente = new JLabel();
				getContentPane().add(jLabelidCliente, BorderLayout.CENTER);
				jLabelidCliente.setText("ID Cliente: ");
				jLabelidCliente.setBounds(16, 28, 91, 28);
			}
			{
				jLabelRazonSocial = new JLabel();
				getContentPane().add(jLabelRazonSocial);
				jLabelRazonSocial.setText("Razon Social : ");
				jLabelRazonSocial.setBounds(14, 77, 98, 14);
			}
			{
				jLabelDireccion = new JLabel();
				getContentPane().add(jLabelDireccion);
				jLabelDireccion.setText("Direccion : ");
				jLabelDireccion.setBounds(14, 119, 98, 14);
			}
			{
				jLabelTelefono = new JLabel();
				getContentPane().add(jLabelTelefono);
				jLabelTelefono.setText("Telefono : ");
				jLabelTelefono.setBounds(14, 168, 98, 14);
			}
			{
				jTextFieldidCliente = new JTextField();
				getContentPane().add(jTextFieldidCliente);
				jTextFieldidCliente.setBounds(112, 28, 91, 21);
			}
			{
				jTextFieldRazonSocial = new JTextField();
				getContentPane().add(jTextFieldRazonSocial);
				jTextFieldRazonSocial.setBounds(114, 74, 183, 23);
			}
			{
				jTextFieldDireccion = new JTextField();
				getContentPane().add(jTextFieldDireccion);
				jTextFieldDireccion.setBounds(115, 119, 182, 23);
			}
			{
				jTextFieldTelefono = new JTextField();
				getContentPane().add(jTextFieldTelefono);
				jTextFieldTelefono.setBounds(115, 165, 182, 23);
			}
			{
				jButtonAltaCliente = new JButton();
				getContentPane().add(jButtonAltaCliente);
				jButtonAltaCliente.setText("Alta Cliente");
				jButtonAltaCliente.setBounds(17, 225, 122, 34);
				jButtonAltaCliente.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						altaCliente();
						}	
					} 
				);
			}
			{
				jButtonCancelar = new JButton();
				getContentPane().add(jButtonCancelar);
				jButtonCancelar.setText("Cancelar");
				jButtonCancelar.setBounds(170, 225, 129, 35);
				jButtonCancelar.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						dispose();
						}	
					} 
				);
			}
			{
				jButtonLimpiar = new JButton();
				getContentPane().add(jButtonLimpiar);
				jButtonLimpiar.setText("Limpiar");
				jButtonLimpiar.setBounds(215, 23, 82, 33);
				jButtonLimpiar.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) 
				{
					jTextFieldTelefono.setText("");
					jTextFieldDireccion.setText("");
					jTextFieldRazonSocial.setText("");
					jTextFieldidCliente.setText("");
					jLabelMensaje.setText("");
					}
				});

			}
			{
				jLabelMensaje = new JLabel();
				getContentPane().add(jLabelMensaje);
				jLabelMensaje.setBounds(17, 198, 295, 21);
			}
			{
				this.setSize(340, 313);
			}
		} catch(Exception e) {
			e.printStackTrace();
		}
	}

	private void altaCliente() {
		ControladorAbmClientes p  = (ControladorAbmClientes) this.controlador;
		p.doAlta_Cliente(Integer.parseInt(jTextFieldidCliente.getText()), jTextFieldRazonSocial.getText(), jTextFieldDireccion.getText(), jTextFieldTelefono.getText());
		jLabelMensaje.setText("EL CLIENTE FUE DADO DE ALTA");
	}
	/**
	* This method should return an instance of this class which does 
	* NOT initialize it's GUI elements. This method is ONLY required by
	* Jigloo if the superclass of this class is abstract or non-public. It 
	* is not needed in any other situation.
	 */
	public static Object getGUIBuilderInstance() {
		return new ClienteAlta(Boolean.FALSE);
	}
	
	/**
	 * This constructor is used by the getGUIBuilderInstance method to
	 * provide an instance of this class which has not had it's GUI elements
	 * initialized (ie, initGUI is not called in this constructor).
	 */
	public ClienteAlta(Boolean initGUI) {
		super();
	}
}
